package com.irdstudio.efp.e4a.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.efp.e4a.service.dao.SRuleExeResultDao;
import com.irdstudio.efp.e4a.service.domain.SRuleExeResult;
import com.irdstudio.efp.e4a.service.facade.SRuleExeResultService;
import com.irdstudio.efp.e4a.service.vo.SRuleExeResultVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;

/**
 * 
 * 系统规则执行结果表
 * 
 * @author Cytus_
 * @since 2018年5月6日 下午3:00:19
 * @version 1.0
 *
 */
@Service("sRuleExeResultService")
public class SRuleExeResultServiceImpl implements SRuleExeResultService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(SRuleExeResultServiceImpl.class);

	@Autowired
	private SRuleExeResultDao sRuleExeResultDao;

	/**
	 * 新增操作
	 */
	@Override
	public int insertSRuleExeResult(SRuleExeResultVO inSRuleExeResultVo) {
		logger.debug("当前新增数据为:" + inSRuleExeResultVo.toString());
		int num = 0;
		try {
			SRuleExeResult sRuleExeResult = new SRuleExeResult();
			beanCopy(inSRuleExeResultVo, sRuleExeResult);
			num = sRuleExeResultDao.insertSRuleExeResult(sRuleExeResult);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	@Override
	public int deleteByPk(SRuleExeResultVO inSRuleExeResultVo) {
		logger.debug("当前删除数据条件为:" + inSRuleExeResultVo);
		int num = 0;
		try {
			SRuleExeResult sRuleExeResult = new SRuleExeResult();
			beanCopy(inSRuleExeResultVo, sRuleExeResult);
			num = sRuleExeResultDao.deleteByPk(sRuleExeResult);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inSRuleExeResultVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	@Override
	public int updateByPk(SRuleExeResultVO inSRuleExeResultVo) {
		logger.debug("当前修改数据为:" + inSRuleExeResultVo.toString());
		int num = 0;
		try {
			SRuleExeResult sRuleExeResult = new SRuleExeResult();
			beanCopy(inSRuleExeResultVo, sRuleExeResult);
			num = sRuleExeResultDao.updateByPk(sRuleExeResult);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inSRuleExeResultVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	@Override
	public SRuleExeResultVO queryByPk(SRuleExeResultVO inSRuleExeResultVo) {

		logger.debug("当前查询参数信息为:" + inSRuleExeResultVo);
		try {
			SRuleExeResult querySRuleExeResult = new SRuleExeResult();
			beanCopy(inSRuleExeResultVo, querySRuleExeResult);
			SRuleExeResult queryRslSRuleExeResult = sRuleExeResultDao.queryByPk(querySRuleExeResult);
			if (Objects.nonNull(queryRslSRuleExeResult)) {
				SRuleExeResultVO outSRuleExeResultVo = beanCopy(queryRslSRuleExeResult, new SRuleExeResultVO());
				logger.debug("当前查询结果为:" + outSRuleExeResultVo.toString());
				return outSRuleExeResultVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<SRuleExeResultVO> queryAllOwner(SRuleExeResultVO sRuleExeResultVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<SRuleExeResultVO> list = null;
		try {
			List<SRuleExeResult> sRuleExeResults = sRuleExeResultDao.queryAllOwnerByPage(sRuleExeResultVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + sRuleExeResults.size());
			pageSet(sRuleExeResults, sRuleExeResultVo);
			list = (List<SRuleExeResultVO>) beansCopy(sRuleExeResults, SRuleExeResultVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<SRuleExeResultVO> queryAllCurrOrg(SRuleExeResultVO sRuleExeResultVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<SRuleExeResult> sRuleExeResults = sRuleExeResultDao.queryAllCurrOrgByPage(sRuleExeResultVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + sRuleExeResults.size());
		List<SRuleExeResultVO> list = null;
		try {
			pageSet(sRuleExeResults, sRuleExeResultVo);
			list = (List<SRuleExeResultVO>) beansCopy(sRuleExeResults, SRuleExeResultVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<SRuleExeResultVO> queryAllCurrDownOrg(SRuleExeResultVO sRuleExeResultVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<SRuleExeResult> sRuleExeResults = sRuleExeResultDao.queryAllCurrDownOrgByPage(sRuleExeResultVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + sRuleExeResults.size());
		List<SRuleExeResultVO> list = null;
		try {
			pageSet(sRuleExeResults, sRuleExeResultVo);
			list = (List<SRuleExeResultVO>) beansCopy(sRuleExeResults, SRuleExeResultVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SRuleExeResultVO> querySRuleExeResultByBizSeron(SRuleExeResultVO sRuleExeResultVo) {

		logger.debug("当前流水号数据信息的参数信息为:" + sRuleExeResultVo.getBizSerno());
		List<SRuleExeResult> sRuleExeResults = sRuleExeResultDao.queryDatasByBizByPage(sRuleExeResultVo);
		logger.debug("当前流水号数据信息的结果集数量为:" + sRuleExeResults.size());
		List<SRuleExeResultVO> list = null;
		try {
			pageSet(sRuleExeResults, sRuleExeResultVo);
			list = (List<SRuleExeResultVO>) beansCopy(sRuleExeResults, SRuleExeResultVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}
}
